﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Shapes;

namespace StickAnimator
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

		private Circle activeCircle;
		private Circle pivotCircle;

		public bool ControlPressed { get; set; }

		private void Form1_MouseMove(object sender, MouseEventArgs e)
		{
			activeCircle.Rotate(pivotCircle, e.X, e.Y);
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			circle1.Partners.Add(circle2);
			circle2.Partners.Add(circle1);
			circle2.Partners.Add(circle3);
			circle3.Partners.Add(circle2);

			activeCircle = circle2;
			activeCircle.MouseMove += new MouseEventHandler(activeControl_MouseMove);

			pivotCircle = circle1;
			pivotCircle.BackColor = Color.GhostWhite;
		}

		void activeControl_MouseMove(object sender, MouseEventArgs e)
		{
			activeCircle.Rotate(pivotCircle, activeCircle.Left + e.X, activeCircle.Top + e.Y);
		}

		private void circle_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Button == System.Windows.Forms.MouseButtons.Left)
			{
				activeCircle.MouseMove -= new MouseEventHandler(activeControl_MouseMove);
				activeCircle = (Circle)sender;
				activeCircle.MouseMove += new MouseEventHandler(activeControl_MouseMove);
			}
			else
				if (activeCircle.Partners.IndexOf((Circle)sender) > -1)
					SetPivot((Circle)sender);
		}

		private void SetPivot(Circle circle)
		{
			pivotCircle.BackColor = Color.Green;
			pivotCircle = circle;
			pivotCircle.BackColor = Color.GhostWhite;
		}
  }
}
